/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-06-28 14:57:15
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-09-02 11:52:22
 * @FilePath: /server/workspace/src/base/util.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"util.h"
#include "base/fiber.h"
namespace Yizhi
{
    pid_t GetThreadid(){
    return syscall(SYS_gettid);
    }
    uint32_t GetFiberid()
    {
        return Fiber::GetFiberId();
    }


    void BackTrace(std::vector<std::string>&bt,int size,int skip){
        void **array=(void **)malloc(sizeof(void*)*size);
        size_t s=::backtrace(array,size);
        char** strings=backtrace_symbols(array,s);
        if(strings==NULL){
            SERVER_LOG_ERROR(SERVER_LOG_ROOT())<<"backtrace_symbols error";
            return;
        }

        for(size_t i=skip;i<s;i++){
            bt.push_back(strings[i]);
        }
        free(array);
        free(strings);
    }
    std::string BackTraceTostring(int skip,int size,std::string prefixName){
        std::vector<std::string> bt;
        BackTrace(bt,size,skip);
        std::stringstream ss;
        for(size_t i=0;i<bt.size();i++){
            ss<<prefixName<<bt[i]<<std::endl;
        }
        return ss.str();
    }


    uint64_t GetcurrentMs(){
        struct timeval tv;
        gettimeofday(&tv,NULL);

        uint64_t milliseconds=tv.tv_sec*1000+(tv.tv_usec)/1000;
        return milliseconds;
    }

    uint64_t GetcurrentUs(){
        struct timeval tv;
        gettimeofday(&tv,NULL);
        uint64_t microseconds=tv.tv_sec*1000000+tv.tv_usec;
        return microseconds;
    }
}
// namespace Yizhi


    